package com.pcs.controller;

import java.text.ParseException;
import java.util.Date;

import org.quartz.SchedulerException;

import com.jfinal.core.Controller;
import com.pcs.common.EasyPage;
import com.pcs.model.Contact;
import com.pcs.model.Remind;
import com.zulin.quartz.Sched;
import com.zulin.utils.DateUtils;
import com.zulin.utils.StringUtils;

public class BirthdayController extends Controller {
	
	DateUtils dateUtils = new DateUtils();
	StringUtils stringUtils = new StringUtils();
	
	public void index() {
		EasyPage easyPage = new EasyPage();
		easyPage.setTotal(Remind.remindDao._paginate(getParaToInt("page"), 10).getTotalRow());
		easyPage.setRows(Remind.remindDao._paginate(getParaToInt("page"), 10).getList());
		renderJson(easyPage);
	}
	
	public void remove() {
		Remind.remindDao.deleteById(getPara("id"));
		renderText("hello");
	}
	
	public void _update() {
		Remind remind = new Remind();
		remind.set("id", getPara("id"));
		remind = Remind.remindDao.findById(getPara("id"));
		remind.set("status", "A");
		
		remind.update();
		
		renderText("hello");
	}
	
	public void save() throws SchedulerException, ParseException {
		
		Contact contact = new Contact();
		String id = getPara("id");
		contact = Contact.contactDao.findById(id);
		
		 
		
		Remind remind = new Remind();
		remind.set("title", "生日提醒(birthday remind)");
		remind.set("content", getPara("content"));
		remind.set("createdate",dateUtils.toString(new Date()));
		remind.set("targetdate", getPara("targetdate"));
		remind.set("reminddate", getPara("reminddate"));
		remind.set("status", "A");
		remind.save();
		
		
		Date reminddate = stringUtils.toDate(getPara("reminddate"));
		String title = "生日提醒(birthday remind)";
		String content = getPara("content");
		String targetdate = getPara("targetdate");
		String createdate = dateUtils.toString(new Date());
		
		
		
		Sched sched = new Sched();
		
		
		sched.setReminddate(reminddate);
		sched.setContent(content);
		sched.setCreatedate(createdate);
		sched.setTargetdate(targetdate);
		sched.setTitle(title);
		
		sched.startShedule();
		renderText("hello");
		
		
	}

}
